package practice10;

import java.util.ArrayList;
import java.util.List;

public class Teacher extends Person{
    private Klass klass;
    private String string;
    private List<Klass> classes = new ArrayList();

    public Teacher(int id, String name, int age, List<Klass> classes) {
        super(id, name, age);
        this.classes = classes;
        StringBuffer c = new StringBuffer();
        if (classes.size() == 0){
            string =super.introduce()+ " I am a Teacher. I teach No Class.";
        }else {
            for (Klass a : classes) {
                c.append(a.getNumber()).append(", ");
            }
            c.deleteCharAt(c.length() - 1);
            String cc = c.deleteCharAt(c.length() - 1).toString();
            string =super.introduce()+ " I am a Teacher. I teach Class "+cc+".";
        }
       }

    public Teacher(int id, String name, int age) {
        super(id, name, age);
        string =super.introduce()+ " I am a Teacher. I teach No Class.";
    }
    public Teacher(int id, String name, int age, Klass klass) {
        super(id, name, age);
        this.klass = klass;
        string =super.introduce()+ " I am a Teacher. I teach Class "+getKlass().getNumber()+".";
    }

    public Klass getKlass() {
        return klass;
    }

    public void setKlass(Klass klass) {
        this.klass = klass;
    }

    public List getClasses() {
        return classes;
    }

    public void setClasses(List classes) {
        this.classes = classes;
    }

    public String introduceWith(Student student){
        String string = null;
        if (klass != student.getKlass()){
            string = super.introduce()+ " I am a Teacher. I don't teach "+student.getName()+".";
        }else if (klass == student.getKlass()){
            string = super.introduce()+ " I am a Teacher. I teach "+student.getName()+".";
        }
        if (classes!=null){
            for (Klass aClass : classes) {
                if (aClass == student.getKlass()){
                    string = super.introduce()+ " I am a Teacher. I teach "+student.getName()+".";
                    break;
                }
            }
        }
        return string;
    }
    public  String introduce(){
        return string;
    }
    
    public boolean isTeaching(Student student){
        boolean flag = false;
        for (Klass aClass : classes) {
            if (aClass.isIn(student)){
                flag = true;
            }

        }
        return flag;
    }
}
